package com.sk.seckilldemo.service;

import com.sk.seckilldemo.entity.ClassesInfo;
import com.sk.seckilldemo.enums.ResultCodeEnum;
import com.sk.seckilldemo.mapper.ClassesMapper;
import com.sk.seckilldemo.util.Response;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品分类功能实现
 * e4glet
 * 2025年7月1日
 * */
@Service
@Transactional //增加事务处理注解
@RequiredArgsConstructor
public class ClassesService {
    private final ClassesMapper classesMapper;

    /**
     * 添加商品分类
     * */
    public Response addClasses(ClassesInfo classes){
        if(classesMapper.addClasses(classes)>0){
            return Response.success(ResultCodeEnum.ADD_CLASSES_SUCCESS);
        }else{
            return Response.error(ResultCodeEnum.ADD_CLASSES_ERROR);
        }
    }

    /**
     * 更新商品分类
     * */
    public Response modifyClasses(ClassesInfo classes){
        if(classesMapper.modifyClasses(classes)>0){
            return Response.success(ResultCodeEnum.UPDATE_CLASSES_SUCCESS);
        }else{
            return Response.error(ResultCodeEnum.UPDATE_CLASSES_ERROR);
        }
    }


    /**
     * 删除商品分类
     * */
    public Response deleteClasses(ClassesInfo classess){
        if(classesMapper.deleteClasses(classess)>0){
            return Response.success(ResultCodeEnum.DELETE_CLASSES_SUCCESS);
        }else{
            return Response.error(ResultCodeEnum.UPDATE_CLASSES_ERROR);
        }
    }

    /**
     * 查询商品分类
     * */
    public Response getClasses(){
        List<ClassesInfo> classesList = classesMapper.getClasses();
        if(classesList!=null){
            return Response.success(ResultCodeEnum.QUERY_CLASSES_SUCCESS,classesList);
        }else{
            return Response.error(ResultCodeEnum.QUERY_CLASSES_ERROR);
        }
    }
}
